package geppetto.phraseHMM.phraseExtraction.phraseAccepter;

import geppetto.phraseHMM.phraseExtraction.extractedphrase.ExtractedPhrasePair;

public class PhraseLengthAcceter extends AbstractPhraseAccepter {

	int maxLengthDiff;
	public PhraseLengthAcceter(int maxLengthDiff) {
		this.maxLengthDiff = maxLengthDiff;
	}

	public boolean acceptPhrase(int sentenceNumber, byte sentenceSource,
			int[] foreignSentence, int[] sourceSentence, int sourceStartPos,
			int sourceEndPos, int foreignStartPos, int foreignEndPos,
			double score) {
		int sourceLen = sourceEndPos - sourceStartPos;
		int foreignLen = foreignEndPos - foreignStartPos;
		return Math.abs(sourceLen - foreignLen) < maxLengthDiff;
	}

	@Override
	public boolean acceptPhrase(ExtractedPhrasePair epp) {
		int foreignEndPos = epp.getForeignEndPos();
		int foreignStartPos = epp.getForeignStartPos();
		int sourceEndPos = epp.getSourceEndPos();
		int sourceStartPos = epp.getSourceStartPos();
		int sourceLen = sourceEndPos - sourceStartPos;
		int foreignLen = foreignEndPos - foreignStartPos;
		return Math.abs(sourceLen - foreignLen) < maxLengthDiff;
	}

}